package view.views;

import java.awt.BorderLayout; 
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;
import javax.swing.JSplitPane;

import view.ToolBar;
import view.components.IpAddressTable;

import view.components.NetworkTree;

import view.listeners.ToolBarListener;
import controller.Controller;

public class StartUpViewPanel extends DefaultContentPanelView {
	private static final long serialVersionUID = 1L;
	final static String Panel_Name = "Home";
	private IpAddressTable ipAdressTable;
	public IpAddressTable getIpAdressTable() {
		return ipAdressTable;
	}

	private NetworkTree networkTree;

	public NetworkTree getNetworkTree() {
		return networkTree;
	}

	public StartUpViewPanel() {
		this.setName(Panel_Name);

	}

	@Override
	public void load() {
		this.removeAll();
		content();

		loadToolBar();

	}

	public void loadToolBar() {
		ToolBar toolBar = Controller.getInstance().getGuiBuilder().getToolBar();
		toolBar.clear();
		ToolBarListener toolBarListener = new ToolBarListener();
		toolBarListener.setTree(networkTree);
		toolBarListener.setTable(ipAdressTable);

		
		
		toolBar.addButton("add.png", toolBarListener, "Host/Subnetz/IP hinzufügen");
		toolBar.addButton("delete.png", toolBarListener, "Host/Subnetz/IP löschen");
		toolBar.addButton("info.png", toolBarListener, "Informationen");
		
	}

	private void content() {
		JPanel panel = new JPanel();
		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
				NetworkTree(), ipAdressTable);
		splitPane.setOneTouchExpandable(true);
		splitPane.setDividerLocation(150);

		// Provide minimum sizes for the two components in the split pane
		// Dimension minimumSize = new Dimension(100, 50);
		// listScrollPane.setMinimumSize(minimumSize);
		// pictureScrollPane.setMinimumSize(minimumSize);

		setLayout(new GridLayout(1, 1));

		add(splitPane);

	}

	private JPanel NetworkTree() {
		JPanel networkPanel = new JPanel();
		networkPanel.setLayout(new GridLayout(1, 1));
		networkTree = new NetworkTree();
		ipAdressTable = new IpAddressTable();
		networkTree.setIpAddressTable(ipAdressTable);

		ipAdressTable.setNetworkTree(networkTree);

		networkPanel.add(networkTree);
		return networkPanel;

	}

}